package com.zh.note.huawei.onehundred.判断字符串子序列;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/9/2 21:01
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String target = sc.nextLine();
        // String source = sc.nextLine();
        String target = "abc";
        String source = "abcaybec";
        StringBuilder targetBuilder = new StringBuilder(target);
        StringBuilder sourceBuilder = new StringBuilder(source);
        targetBuilder.reverse();
        sourceBuilder.reverse();


        int step = -1;
        int count = targetBuilder.length();
        char[] chars = targetBuilder.toString().toCharArray();
        for (char ch : chars) {
            int i = sourceBuilder.indexOf(String.valueOf(ch));
            if (step < i) {
                step = i;
                count--;
            }

        }
        if (count != 0) {
            System.out.println(-1);
        } else {
            System.out.println(sourceBuilder.length() - step - 1);
        }

    }
}
